package com.id.supaclean.ui.junk

import android.widget.ImageView
import androidx.core.os.bundleOf
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import com.id.supaclean.R
import com.id.supaclean.common.BaseFragment
import kotlinx.coroutines.delay

/**
 * Created by YiGo on 2022/6/15.
 */
class JunkCleanFragment : BaseFragment() {
    override fun layoutId(): Int = R.layout.fragment_junk_clean
    val viewModel by lazy { ViewModelProvider(this.requireActivity()).get(JunkViewModel::class.java) }

    override fun initView() {
        super.initView()
        view?.findViewById<ImageView>(R.id.junk_fragment_back_iv)?.setOnClickListener {
            activity?.finish()
        }
    }

    override fun initEvent() {
        super.initEvent()
        lifecycleScope.launchWhenResumed {
            delay(5000)
            var finishNum: String? = null
            if (viewModel.currentPreGarbageNum.value != null && viewModel.currentPreGarbageUnit.value != null) {
                finishNum =
                    viewModel.currentPreGarbageNum.value + viewModel.currentPreGarbageUnit.value
            }
            val bundle = bundleOf("finish_num" to finishNum)
            navigate(R.id.action_junkCleanFragment_to_cleanFinishFragment, bundle)
        }
    }


}